package Test;
import model.User;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class BusinessService {
	public static SessionFactory sessionFactory;
	static {
		try{
			Configuration config =new Configuration().configure();
			sessionFactory=config.buildSessionFactory();
		}catch(RuntimeException e){
			e.printStackTrace();
			throw e;
		}
	}
	
		/**
		 * 测试组成模型的添加方法
		 */
		private void saveUser() {
			Session	session=sessionFactory.openSession();
			Transaction tx=session.beginTransaction();
			User user=new User();
			user.setUsername("shenli");
			user.setPassword("123");
			session.save(user);
			tx.commit();
			session.close();
			
		}

	public void test(){
		saveUser();
	}
	
	public static void main(String args[]){
		new BusinessService().test();
		sessionFactory.close();
	}

}
